<template>
	<view class="edit-circle-container">
		<!-- 头部区域 -->
		<headerSlot :propsColor="'#fff'">
			<template v-slot:header>
				<view class="header-content" @click="closePage()">
					<view class="header-left">
						<view class="back-btn">
							<text class="back-icon">←</text>
						</view>
					</view>
                    <view class="header-center">
                        <text class="page-title">{{ isEditMode ? '编辑帖子' : '发布帖子' }}</text>
                    </view>
					<view class="header-right">
						<view class="placeholder"></view>
					</view>
				</view>
			</template>
		</headerSlot>

		<!-- 主要内容区域 -->
		<view class="main-content">
			<!-- 圈子类型选择 -->
			<view class="type-selection-card">
				<view class="card-header">
					<view class="header-title">
						<text class="title-text">圈子类型</text>
						<view class="title-decoration"></view>
					</view>
				</view>
				
				<view class="type-tags">
					<view 
						class="type-tag" 
						:class="{'active': tagType == 'A'}"
						@click="changeTag('A')"
					>
						<view class="tag-content">
							<view class="tag-icon-wrapper">
								<text class="tag-icon">🏠</text>
							</view>
							<text class="tag-text">邻里日常</text>
							<view class="tag-subtitle">分享生活点滴</view>
						</view>
						<view class="tag-check" v-if="tagType == 'A'">
							<text class="check-icon">✓</text>
						</view>
					</view>
					
					<view 
						class="type-tag" 
						:class="{'active': tagType == 'B'}"
						@click="changeTag('B')"
					>
						<view class="tag-content">
							<view class="tag-icon-wrapper">
								<text class="tag-icon">🔍</text>
							</view>
							<text class="tag-text">失物招领</text>
							<view class="tag-subtitle">寻找失物或招领</view>
						</view>
						<view class="tag-check" v-if="tagType == 'B'">
							<text class="check-icon">✓</text>
						</view>
					</view>
					
					<view 
						class="type-tag" 
						:class="{'active': tagType == 'C'}"
						@click="changeTag('C')"
					>
						<view class="tag-content">
							<view class="tag-icon-wrapper">
								<text class="tag-icon">🛍️</text>
							</view>
							<text class="tag-text">邻里闲置</text>
							<view class="tag-subtitle">闲置物品交易</view>
						</view>
						<view class="tag-check" v-if="tagType == 'C'">
							<text class="check-icon">✓</text>
						</view>
					</view>
				</view>
			</view>

			<!-- 动态内容区域 -->
			<view class="dynamic-content">
				<LeaveUnused v-if="tagType == 'C'" :circleInfo="editCircle" />
				<LostFound v-if="tagType == 'B'" :circleInfo="editCircle" />
				<NeighborhoodDaily v-if="tagType == 'A'" :circleInfo="editCircle" />
			</view>
		</view>
	</view>
</template>

<script>
	import headerSlot from '@/components/header-slot.vue';
	import LeaveUnused from './components/--leave--unused.vue';
	import LostFound from './components/--lost--Found.vue';
	import NeighborhoodDaily from './components/--neighborhood--Daily.vue';
	import {
		mapState
	} from "vuex"
	
	export default {
		components: {
			headerSlot,
			LeaveUnused,
			LostFound,
			NeighborhoodDaily
		},
		data() {
			return {
				tagType: 'A',
                isEditMode: false,
			};
		},
		onLoad(opt) {
            // 判断是否编辑模式（store 中是否存在 editCircle._id）
            this.isEditMode = !!(this.editCircle && this.editCircle._id)

            if (this.editCircle && this.editCircle.type == "邻里闲置") {
				this.tagType = 'C'
			} else if (this.editCircle && this.editCircle.type == "失物招领") {
				this.tagType = 'B'
			} else {
				this.tagType = 'A'
				if (opt.type) {
					this.tagType = opt.type
				}
			}
		},
		methods: {
			closePage() {
				uni.navigateBack()
			},
			changeTag(type) {
				this.$store.commit('setEditCircle', {})
				this.tagType = type
			}
		},
		computed: {
			...mapState(['editCircle']),
			circleInfo() {
				return this.editCircle || {}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.edit-circle-container {
		background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
		min-height: 100vh;
	}

	// 头部样式
	.header-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 32rpx;
		width: 100%;
		
		.header-left {
			.back-btn {
				width: 64rpx;
				height: 64rpx;
				background: rgba(255, 255, 255, 0.9);
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
				transition: all 0.3s ease;
				
				&:active {
					transform: scale(0.95);
					background: rgba(255, 255, 255, 1);
				}
				
				.back-icon {
					font-size: 32rpx;
					color: #333;
					font-weight: 600;
				}
			}
		}
		
		.header-center {
			flex: 1;
			text-align: center;
			
			.page-title {
				font-size: 36rpx;
				font-weight: 700;
				color: #333;
			}
		}
		
		.header-right {
			.placeholder {
				width: 64rpx;
			}
		}
	}

	// 主要内容区域
	.main-content {
		padding: 24rpx;
	}

	// 类型选择卡片
	.type-selection-card {
		background: white;
		border-radius: 24rpx;
		padding: 32rpx;
		margin-bottom: 24rpx;
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
		
		.card-header {
			margin-bottom: 32rpx;
			
			.header-title {
				display: flex;
				align-items: center;
				
				.title-text {
					font-size: 32rpx;
					font-weight: 700;
					color: #333;
					margin-right: 16rpx;
				}
				
				.title-decoration {
					width: 6rpx;
					height: 28rpx;
					background: linear-gradient(135deg, #FF6B35 0%, #FE6100 100%);
					border-radius: 3rpx;
				}
			}
		}
		
		.type-tags {
			display: flex;
			flex-direction: row;
			gap: 12rpx;
			
			.type-tag {
				flex: 1;
				background: white;
				border-radius: 16rpx;
				padding: 20rpx 12rpx;
				transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
				border: 2rpx solid #f0f0f0;
				position: relative;
				overflow: hidden;
				box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
				
				&:active {
					transform: scale(0.98);
				}
				
				&.active {
					
					.tag-text {
						color: white;
						font-weight: 700;
					}
					
					.tag-subtitle {
						color: rgba(255, 255, 255, 0.8);
					}
					
					.tag-icon-wrapper {
						background-color: rgba(255, 255, 255, 0.2);
					}
					
					&::before {
						content: '';
						position: absolute;
						top: 0;
						left: 0;
						right: 0;
						bottom: 0;
						background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
						animation: tagShine 2s ease-in-out infinite;
					}
				}
				
				.tag-content {
					display: flex;
					flex-direction: column;
					align-items: center;
					position: relative;
					z-index: 1;
					
					.tag-icon-wrapper {
						width: 48rpx;
						height: 48rpx;
						border-radius: 12rpx;
						background: linear-gradient(135deg, #FF6B35 0%, #FE6100 100%);
						display: flex;
						align-items: center;
						justify-content: center;
						margin-bottom: 8rpx;
						box-shadow: 0 4rpx 16rpx rgba(254, 97, 0, 0.2);
					}
					
					.tag-icon {
						font-size: 24rpx;
						color: white;
					}
					
					.tag-text {
						font-size: 24rpx;
						color: #333;
						font-weight: 700;
						transition: all 0.3s ease;
						margin-bottom: 4rpx;
						text-align: center;
					}

					.tag-subtitle {
						font-size: 20rpx;
						color: #999;
						transition: all 0.3s ease;
						text-align: center;
					}
				}

				.tag-check {
					position: absolute;
					top: 6rpx;
					right: 6rpx;
					width: 28rpx;
					height: 28rpx;
					background-color: #FF6B35;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
					z-index: 2;

					.check-icon {
						font-size: 18rpx;
						color: white;
						font-weight: 700;
					}
				}
			}
		}
	}

	// 动态内容区域
	.dynamic-content {
		background: white;
		border-radius: 24rpx;
		overflow: hidden;
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
	}

	@keyframes tagShine {
		0% {
			transform: translateX(-100%);
		}
		50% {
			transform: translateX(100%);
		}
		100% {
			transform: translateX(100%);
		}
	}

	// 兼容旧样式
	.header_slot {
		padding: 0 32rpx;
		width: 100%;
		font-weight: 500;
		font-size: 36rpx;
		color: #2C2622;
	}

	.card_box {
		padding: 32rpx;

		.release_btn {
			margin-top: 32rpx;
		}
	}

	.tag_box {
		border-top: 1px solid #ccc;
		padding: 32rpx 0;
		margin: 0 32rpx;
	}

	.cu-item {
		margin: 0 !important;
	}

	::v-deep .icon-add {
		height: 2px !important;
		background-color: orange;
	}
</style>